package cn.xaut.数组;

import java.util.Arrays;

public class demo26 {

    public int removeDuplicates(int[] nums) {

        int len = nums.length;
        if (len == 0)
            return 0;
        
        int index = 0;
        for (int i = 1; i < len; i++) {
            if (nums[i] != nums[index]){ 
                index ++;    
                nums[index] = nums[i];
            }
        }
        
        return index + 1;
    }

    public static void main(String[] args) {

        int[] nums = new int[]{0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
        System.out.println(new demo26().removeDuplicates(nums));
        System.out.println(Arrays.toString(nums));
    }
}
